package util.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import util.enumeration.CuisineType;
import util.enumeration.FnbType;

@FacesConverter(value = "cuisineTypeConverter", forClass = util.enumeration.CuisineType.class)
public class CuisineTypeConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {    

        if (value == null || value.length() == 0) {
            return null;
        }

        if(value.equals("CANTONESE")) return CuisineType.CANTONESE;
        else if(value.equals("CHINESE")) return CuisineType.CHINESE;
        else if(value.equals("FUJIAN")) return CuisineType.FUJIAN;
        else if(value.equals("HAINANESE")) return CuisineType.HAINANESE;
        else if(value.equals("HAKKA")) return CuisineType.HAKKA;
        else if(value.equals("HOKKIEN")) return CuisineType.HOKKIEN;
        else if(value.equals("INDIAN")) return CuisineType.INDIAN;
        else if(value.equals("JAPANESE")) return CuisineType.JAPANESE;
        else if(value.equals("KOREAN")) return CuisineType.KOREAN;
        else if(value.equals("MALAY")) return CuisineType.MALAY;
        else if(value.equals("SHANGHAI")) return CuisineType.SHANGHAI;
        else if(value.equals("TEOCHEW")) return CuisineType.TEOCHEW;
        else if(value.equals("WESTERN")) return CuisineType.WESTERN;
        else if(value.equals("XINJIANG")) return CuisineType.XINJIANG;
        else return CuisineType.XINJIANG;
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {

        if (value == null) {
            return null;
        }

        if (value instanceof CuisineType) {
            CuisineType cuisineType = (CuisineType) value;

            if(cuisineType.equals(CuisineType.CANTONESE)) return "CANTONESE";
            else if(cuisineType.equals(CuisineType.CHINESE)) return "CHINESE";
            else if(cuisineType.equals(CuisineType.FUJIAN)) return "FUJIAN";
            else if(cuisineType.equals(CuisineType.HAINANESE)) return "HAINANESE";
            else if(cuisineType.equals(CuisineType.HAKKA)) return "HAKKA";
            else if(cuisineType.equals(CuisineType.HOKKIEN)) return "HOKKIEN";
            else if(cuisineType.equals(CuisineType.INDIAN)) return "INDIAN";
            else if(cuisineType.equals(CuisineType.JAPANESE)) return "JAPANESE";
            else if(cuisineType.equals(CuisineType.KOREAN)) return "KOREAN";
            else if(cuisineType.equals(CuisineType.MALAY)) return "MALAY";
            else if(cuisineType.equals(CuisineType.SHANGHAI)) return "SHANGHAI";
            else if(cuisineType.equals(CuisineType.TEOCHEW)) return "TEOCHEW";
            else if(cuisineType.equals(CuisineType.WESTERN)) return "WESTERN";
            else if(cuisineType.equals(CuisineType.XINJIANG)) return "XINJIANG";
            else return "XINJIANG";
        }
        else {
            throw new IllegalArgumentException("object " + value + " is of type " + value.getClass().getName() + "; expected type: util.enumeration.CuisineType");
        }
    }
}